//
//  YFArrowButton.m
//  QuanJieShopProject
//
//  Created by 杨帆 on 2018/3/29.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "YFArrowButton.h"

@implementation YFArrowButton

/**
 * init方法内部会调用这个方法
 * 只有通过代码创建控件,才会执行这个方法
 */
- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self setup];
    }
    return self;
}

/**
 * 通过xib\storyboard创建控件时,才会执行这个方法
 */
- (id)initWithCoder:(NSCoder *)decoder {
    if (self = [super initWithCoder:decoder]) {
        [self setup];
    }
    return self;
}

/**
 * 初始化
 */
- (void)setup
{
    
//    [self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    self.titleLabel.font = [UIFont systemFontOfSize:14];
    // down
    [self setImage:[UIImage imageNamed:@"down-3"] forState:UIControlStateNormal];
    // up
    [self setImage:[UIImage imageNamed:@"down-3"] forState:UIControlStateSelected];
}

- (void)layoutSubviews
{
    [super layoutSubviews]; // 这时的self.frame 还是空
    
//    NSLog(@"x = %f, y = %f", self.frame.origin.x, self.mj_y);
    self.titleLabel.mj_x = self.imageView.mj_x;// 图片的位置不对,所以减去40
    self.imageView.mj_x = CGRectGetMaxX(self.titleLabel.frame);
}

//- (void)setTitle:(NSString *)title forState:(UIControlState)state
//{
//    [super setTitle:title forState:state];
//    [self sizeToFit];
//}
//
//- (void)setImage:(UIImage *)image forState:(UIControlState)state
//{
//    [super setImage:image forState:state];
//    [self sizeToFit];
//}

@end
